#define DEBUG
#include <cstdio>
#define MAXN 300000
#define MAXM 300000

using namespace std;

inline int min(int a, int b) {
  return a<b ? a : b;
}

inline int max(int a, int b) {
  return a>b ? a : b;
}

int read() {
  int ret=0;
  char c=getchar();
  for (; c<'0' || c>'9'; c=getchar());
  for (; c>='0' && c<='9'; c=getchar()) {
    ret = ret*10+c-'0';
  }
  return ret;
}

int getFa(int *set, int o) {
  if (set[o]!=o) {
    set[o] = getFa(set, set[o]);
  }
  return set[o];
}

class Tree {
public:
  int n, m, nq, mq, ind[MAXN+1], to[2*MAXN-1], link[2*MAXN-1], val[2*MAXN-1], lca_set[MAXN+1], ques[MAXM+1][4], indq[MAXN+1], linkq[2*MAXM+1], toq[2*MAXM+1], posq[2*MAXM+1], dep[MAXN+1], fav[MAXN+1][2], from[MAXN+1], mark[MAXN+1];
  bool flag[MAXN+1];

  void addSide(int a, int b, int t) {
    m++;
    to[m] = b;
    val[m] = t;
    link[m] = ind[a];
    ind[a] = m;
  }

  void addQues(int a, int b) {
    nq++;
    ques[nq][1] = a, ques[nq][2] = b;
    mq++;
    toq[mq] = b;
    posq[mq] = nq;
    linkq[mq] = indq[a];
    indq[a] = mq;
    mq++;
    toq[mq] = a;
    posq[mq] = nq;
    linkq[mq] = indq[b];
    indq[b] = mq;
  }

  void tarjan(int o, int fa) {
    flag[o]=true;
    lca_set[o] = o;
    from[o]=o;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	dep[to[i]] = dep[o]+val[i];
	fav[to[i]][1] = val[i];
	fav[to[i]][0] = o;
	tarjan(to[i], o);
	lca_set[to[i]] = o;
      }
    }
    for (int i=indq[o]; i; i=linkq[i]) {
      if (flag[toq[i]]) {
	ques[posq[i]][0]=getFa(lca_set, toq[i]);
	ques[posq[i]][3]=dep[toq[i]]+dep[o]-2*dep[ques[posq[i]][0]];
      }
    }
  }

  void up1(int o, int tar, int *ans) {
    ans[0]=0;
    for (; o!=tar; o=fav[o][0]) {
      ans[++ans[0]]=fav[o][1];
      mark[o]=ans[0];
    }
    mark[tar]=ans[0]+1;
  }

  void up2(int o, int tar, int *ans) {
    static int temp[MAXN+1];
    temp[0]=0;
    int x=o;
    for (; o!=tar; o=fav[o][0]) {
      temp[++temp[0]]=fav[o][1];
    }
    for (; temp[0]>0; temp[0]--) {
      ans[++ans[0]]=temp[temp[0]];
    }
    for (int i=0; x!=tar; x=fav[x][0], i++) {
      mark[x]=ans[0]+1-i;
    }
  }

  void rebuild(int o) {
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fav[o][0]) {
	rebuild(to[i]);
	if (!mark[to[i]]) {
	  from[to[i]] = o;
	}
      }
    }
  }
};

int main() {
  freopen("transport.in", "r", stdin);
  freopen("transport.out", "w", stdout);

  static Tree tree;
  int n=tree.n=read(), m=read();
  for (int i=1; i<n; i++) {
    int a=read(), b=read(), t=read();
    tree.addSide(a, b, t);
    tree.addSide(b, a, t);
  }
  for (int i=1; i<=m; i++) {
    int u=read(), v=read();
    tree.addQues(u, v);
  }
  tree.tarjan(1, 0);

  int ans, maxp=1;
  for (int i=1; i<=n; i++) {
    if (tree.ques[i][3]>tree.ques[maxp][3]) {
      maxp = i;
    }
  }
  ans = tree.ques[maxp][3];
  static int line[MAXN+1], l[MAXN+1], r[MAXN+2];
  tree.up1(tree.ques[maxp][1], tree.ques[maxp][0], line);
  tree.up2(tree.ques[maxp][2], tree.ques[maxp][0], line);
  tree.rebuild(1);
  tree.from[1]=tree.ques[maxp][0];
  for (int i=1; i<=m; i++) {
    int x=tree.mark[getFa(tree.from, tree.ques[i][1])], y=tree.mark[getFa(tree.from, tree.ques[i][2])];
    if (x<y) {
      r[x]=max(r[x], tree.ques[i][3]);
      l[y]=max(l[y], tree.ques[i][3]);
    } else {
      r[y]=max(r[y], tree.ques[i][3]);
      l[x]=max(l[x], tree.ques[i][3]);
    }
  }
  for (int i=1; i<=line[0]+1; i++) {
    l[i]=max(l[i], l[i-1]);
  }
  for (int i=line[0]+1; i>0; i--) {
    r[i]=max(r[i], r[i+1]);
  }
  for (int i=1; i<=line[0]; i++) {
    ans=min(ans, max(tree.ques[maxp][3]-line[i], max(l[i], r[i+1])));
  }

  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
